package khleuven.mondzorg.domain;

import khleuven.mondzorg.Logger;

import org.json.JSONObject;

public class Faq extends Entry {
	
	private String faq;
	private String explanation;

	@Deprecated
	public Faq(Language language, DestinationGroup destination, String faq, String explanation) throws DomainException {
		super(EntryType.FAQ, language, destination);
		setFaq(faq);
		setExplanation(explanation);
	}
	
	public Faq(JSONObject object) throws DomainException{
		super(EntryType.FAQ, object);		
		setFaq(JsonKeysDictionary.getStringItem(object, JsonKeysDictionary.JSON_KEY_FAQ_NAME));
		setExplanation(JsonKeysDictionary.getStringItem(object, JsonKeysDictionary.JSON_KEY_FAQ_EXPLANATION));
		Logger.logDomain(toString());
	}
	
	public String getFaq() {
		return faq;
	}

	public void setFaq(String faq) {
		this.faq = faq;
	}

	public String getExplanation() {
		return explanation;
	}

	public void setExplanation(String explanation) {
		this.explanation = explanation;
	}
	
	@Override
	public String makeStringForList() {
		return getFaq();
	}
	
	@Override
	public String toString(){
		return super.toString()+getFaq()+" - "+getExplanation();				
	}
	
	@Override
	public JSONObject toJSon() throws DomainException {
		JSONObject output = super.toJSon();
		JsonKeysDictionary.toStringItem(output, JsonKeysDictionary.JSON_KEY_FAQ_NAME, getFaq());
		JsonKeysDictionary.toStringItem(output, JsonKeysDictionary.JSON_KEY_FAQ_EXPLANATION, getExplanation());
		return output;
	}
	
	@Override
	public boolean equals(Object obj) {
		boolean gelijk = false;
		if(obj instanceof Faq){
			Faq f = (Faq)(obj);
			if(super.equals(f) && 
				f.getFaq().equals(this.getFaq()) &&
				f.getExplanation().equals(this.getExplanation())){
				gelijk = true;
			}
		}
		return gelijk;	
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((explanation == null) ? 0 : explanation.hashCode());
		result = prime * result + ((faq == null) ? 0 : faq.hashCode());
		return result;
	}

	@Override
	public int compareTo(Entry t) {
		int r = super.compareTo(t);
		if(r == 0) {
			Faq o = (Faq)t; 
			// CCE not possible because of super.compareTo(t)
			return this.getFaq().compareTo(o.getFaq());
		} else {
			return r;
		}
	}
}